--[[          SLDT: Simple Light Data Text				]]
--[[ Author: Taffu	Rev Date: 2/15/11	Version: 3.1.1	]]

--[[ ****************************
v3.1.1
- Fixed bug related to combat fading
  and tracker enable state
****************************** ]]

local SLDT = CreateFrame("Frame")
local Click, Media = LibStub("SLClickConfigLib-1.0"), LibStub("LibSharedMedia-3.0")
local deFont, modbg = Media:Fetch("font", "Arial Narrow"), { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = { left = 0, top = 0, right = 0, bottom = 0 } }
local sf, su = string.format, string.upper
local repMem, classColor, class, db = false, "|cffffffff", nil
local function err(msg) if type(msg) ~= "string" then tostring(msg) end; ChatFrame1:AddMessage(sf("SLDT ERROR - %s", msg)) end

--[[ -----Default Saved Var Settings----- ]]
SLDT_DEFAULTS = {
	general = {
		confMode = false, moving = false,
		fade = true, font = "Arial Narrow",
		classCol = true,
	},
	clock = {
		name = "sldt_clock", enabled = true, cbfade = false,
		int = 2, format24 = false, realmTime = false, outline = true,
		aP = "CENTER", aF = "CENTER", anch = "UIParent",
		xOff = -100, yOff = -100, fontSize = 12, enname = "Clock",
	},
	fps = {
		name = "sldt_fps", enabled = true, cbfade = false, int = 5,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 100, yOff = -100, fontSize = 12, enname = "FPS",
	},
	lag = {
		name = "sldt_lag", enabled = true, cbfade = false, int = 5,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = -200, yOff = -100, fontSize = 12, enname = "Latency",
	},
	mem = {
		name = "sldt_mem", enabled = true, cbfade = false, int = 10,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 200, yOff = -100, fontSize = 12, enname = "Memory",
	},
	money = {
		name = "sldt_gold", enabled = true, cbfade = false, dispSty = false,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 0, yOff = -100, fontSize = 12, enname = "Money", curDisp = "Gold",
	},
	xp = {
		name = "sldt_xp", enabled = true, cbfade = false, dispSty = true,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 0, yOff = 100, fontSize = 12, enname = "Experience",
		repMode = false, wF = 50,
	},
	bag = {
		name = "sldt_bag", enabled = true, cbfade = false,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = -100, yOff = 100, fontSize = 12, autosell = false, enname = "Bag",
	},
	dura = {
		name = "sldt_dura", enabled = true, cbfade = false,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 100, yOff = 100, fontSize = 12, autorepair = false, 
		enname = "Durability",
	},
	mail = {
		name = "sldt_mail", enabled = true, cbfade = false, int = 10,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = -200, yOff = 100, fontSize = 12, enname = "Mail",
	},
	social = {
		name = "sldt_social", enabled = true, cbfade = false,
		aP = "CENTER", aF = "CENTER", anch = "UIParent", outline = true,
		xOff = 200, yOff = 100, fontSize = 12, enname = "Social",
		showF = true, showG = true, int = 5,
	},
}
--[[ ------------------------------------ ]]

local clock, fps, lag, mem, money, xp, bag, dura, mail, social = SLDT_DEFAULTS.clock, SLDT_DEFAULTS.fps, SLDT_DEFAULTS.lag, SLDT_DEFAULTS.mem, SLDT_DEFAULTS.money, SLDT_DEFAULTS.xp, SLDT_DEFAULTS.bag, SLDT_DEFAULTS.dura, SLDT_DEFAULTS.mail, SLDT_DEFAULTS.social

local function Build(item, itemDB)
	local item_name = item.name
	if not item.frame then item.frame = CreateFrame("Frame", item_name, UIParent) else return end
	item.frame:SetBackdrop(modbg); item.frame:SetBackdropColor(0,0,0,0)
	item.string = item.frame:CreateFontString(nil, "OVERLAY")
	item.string:SetFont(Media:Fetch("font", db.general.font) or deFont, itemDB.fontSize)
	item.string:SetPoint("CENTER", item_name, "CENTER", 0, 0)
	item.frame:Show()
end

local function RefreshFrame(item, itemDB)
	item.string:SetFont(Media:Fetch("font", db.general.font), itemDB.fontSize, itemDB.outline and "THINOUTLINE" or nil)
	if not itemDB.outline then item.string:SetShadowColor(0,0,0,1); item.string:SetShadowOffset(1.25, -1.25) else item.string:SetShadowColor(0,0,0,0) end
	item.frame:SetWidth(item.string:GetWidth()); item.frame:SetHeight(item.string:GetHeight())
	item.frame:SetPoint(itemDB.aP, itemDB.anch, itemDB.aF, itemDB.xOff, itemDB.yOff)
end

--[[ -----Additional Info & Functions----- ]]
local locTime
local friendsOnline, guildiesOnline = 0, 0
local curCycle = {}
local function getGameTime()
    local serTime, serAMPM
    local hour, minu = GetGameTime()
	if minu < 10 then minu = sf("%s%s", "0", tostring(minu)) end 
    if db.clock.format24 then
        serAMPM = ""; serTime = sf("%i:%d", hour, minu)
    else
        if hour > 11 then serAMPM = "pm" else serAMPM = "am" end
        if hour == 0 then hour = hour + 12 elseif hour > 12 then hour = hour - 12 end
        serTime = sf("%i:%d", hour, minu)
    end
    return serTime, serAMPM
end
local function convertMoney(moolah, display)
    local g, s, c = abs(moolah/10000), abs(mod(moolah/100, 100)), abs(mod(moolah, 100))
	local cash
    if display then
		if g < 1 then g = "" else g = sf("%d|cffffd700g|r ", g) end
		if s < 1 then s = "" else s = sf("%d|cffc7c7cfs|r ", s) end
		c = sf("%d|cffeda55fc|r", c)
        cash = sf("%s%s%s", g, s, c)
    else
        cash = sf("%.1f|cffffd700g|r", g)
    end
    return cash
end
local function getPTime(s)
	local t
	local d,h,m,s = ChatFrame_TimeBreakDown(s)
	if d == 0 then d = nil end; if h == 0 then h = nil end; if m == 0 then m = nil end
	t = sf("%s%s%s", d and sf("%dd ", d) or "", h and sf("%dh ", h) or "", m and sf("%dm ", m) or "")
	return t
end
local function getXPStr(typ)
	local curXP, maxXP, resXP, str = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion(), nil
	if typ == "cur" then if maxXP > 1000 then str = sf("%i%sk|r", curXP/1000, classColor) else str = sf("%i", curXP) end end
	if typ == "max" then if maxXP > 1000 then str = sf("%i%sk|r", maxXP/1000, classColor) else str = sf("%i", maxXP) end end
	if typ == "rem" then if maxXP > 1000 then str = sf("%i%sk|r", (maxXP-curXP)/1000, classColor) else str = sf("%i", maxXP-curXP) end end
	if typ == "per" then str = sf("%s(|r%.0f%%%s)|r", classColor, curXP*(100/maxXP), classColor) end
	if typ == "perR" then str = sf("%s(|r%.0f%%%s)|r", classColor, 100-(curXP*(100/maxXP)), classColor) end
	if typ == "rest" then if resXP > 1000 then str = sf("%i%sk|r", resXP/1000, classColor) else str = sf("%i", resXP) end end
	if typ == "rper" then str = sf(" %s[|r%.0f%%%s]|r", classColor, resXP*(100/maxXP), classColor) end
	if typ == nil then str = "No xp data" end
	return str
end
local function getClass(cl)
	local cls
	if GetLocale() == "frFR" then
		local L = {}
		L["Guerrier"] = "WARRIOR"
		L["Guerrière"] = "WARRIOR"
		L["Druide"] = "DRUID"
		L["Druidesse"] = "DRUID"
		L["Voleur"] = "ROGUE"
		L["Voleuse"] = "ROGUE"
		L["Prêtre"] = "PRIEST"
		L["Prêtresse"] = "PRIEST"
		L["Chevalier de la mort"] = "DEATHKNIGHT"
		L["Chaman"] = "SHAMAN"
		L["Chamane"] = "SHAMAN"
		L["Paladin"] = "PALADIN"
		L["Mage"] = "MAGE"
		L["Démoniste"] = "WARLOCK"
		L["Chasseresse"] = "HUNTER"
		L["Inconnu"] = "UNKNOWN"
		cls = L[cl]
	else
		local L = {}
		L["Warrior"] = "WARRIOR"
		L["Druid"] = "DRUID"
		L["Rogue"] = "ROGUE"
		L["Priest"] = "PRIEST"
		L["Death Knight"] = "DEATHKNIGHT"
		L["Shaman"] = "SHAMAN"
		L["Paladin"] = "PALADIN"
		L["Mage"] = "MAGE"
		L["Warlock"] = "WARLOCK"
		L["Hunter"] = "HUNTER"
		L["Unknown"] = "UNKNOWN"
		cls = L[cl]
	end
	return cls
end
--[[ ------------------------------------- ]]

--[[ Refresh Functions ]]
local function updateClock()
	local hr, mi = db.clock.format24 and "%H" or "%I", "%M"
	local hour, minute, meridian = date(hr), date(mi), date("%p")
	locTime = sf("%i:%s%s%s|r", hour, minute, classColor, string.lower(meridian))
	rlmTime = sf("%s%s%s|r", select(1, getGameTime()), classColor, select(2, getGameTime()))
	clock.string:SetText(db.clock.realmTime and rlmTime or locTime)
	RefreshFrame(clock, db.clock)
end
local function updateFPS()
	local fr = GetFramerate()
	fps.string:SetFormattedText("%.0f%sfps|r", fr, classColor)
	RefreshFrame(fps, db.fps)
end
local function updateLag()
	local bandin, bandout, latency = GetNetStats()
	lag.string:SetFormattedText("%i%sms|r", latency, classColor)
	RefreshFrame(lag, db.lag)
end
local function updateMem()
	UpdateAddOnMemoryUsage()
	local total = 0
	for i = 1, GetNumAddOns() do
		if select(1, GetAddOnInfo(i)) == "SLDT" and repMem then print(sf("%s mem usage is %.1fkb", select(1, GetAddOnInfo(i)), GetAddOnMemoryUsage(i))) end
		if IsAddOnLoaded(i) then
			total = total + GetAddOnMemoryUsage(i)
		end
	end
	mem.string:SetFormattedText("%.1f%smb|r", total/1024, classColor)
	RefreshFrame(mem, db.mem)
end
local goldStart, goldEarned, loggedOn, curGold = 0, 0, true, 0
local currTable = {}
local function updateMoney()
	curGold = GetMoney()
	local moneyTxt = convertMoney(curGold, db.money.dispSty)
	if loggedOn then 
		goldStart = curGold; loggedOn = false
	else
		if curGold - goldStart ~= 0 then goldEarned = curGold - goldStart end
	end
	money.string:SetText(moneyTxt)
	RefreshFrame(money, db.money)
end
local function updateCurrency()
	local size = GetCurrencyListSize()
	for i = 1, size do
		local name, isHeader, isExpanded, isUnused, isWatched, count, extraCurrencyType, icon, itemID = GetCurrencyListInfo(i)
		if not isHeader and count > 0 then
			currTable[name] = count
			--currTable[name]["string"] = sf("%s: %d", name, count)
		end
	end
end
local function updateXP(event)
	if event == "UPDATE_FACTION" and db.xp.repMode then
		-- Do rep stuff
	else
		xp.string:SetFormattedText("%s/%s %s%s", getXPStr("cur"), getXPStr("max"), getXPStr("per"), GetXPExhaustion() and getXPStr("rper") or "")
	end
	RefreshFrame(xp, db.xp)
end
local function updateBag()
	local bagRem, bagTtl = 0, 0
	for i = 0, NUM_BAG_SLOTS do
		bagRem, bagTtl = bagRem + GetContainerNumFreeSlots(i), bagTtl + GetContainerNumSlots(i)
	end
	bag.string:SetFormattedText("%sB:|r %d/%d", classColor, bagRem, bagTtl)
	RefreshFrame(bag, db.bag)
end
local function updateDura()
	local durMin, durCol = 100, "FFFFFF"
	for i = 1, 18 do
		local durCur, durMax = GetInventoryItemDurability(i)
		if durCur ~= durMax then durMin = min(durMin, durCur*(100/durMax)) end
	end
	if durMin < 60 then durCol = "FFFF00" elseif durMin < 30 then durCol = "FF0000" end
	dura.string:SetFormattedText("%sD:|r |cff%s%.0f|r%%", classColor, durCol, durMin)
	RefreshFrame(dura, db.dura)
end
local function updateMail()
	mail.string:SetFormattedText("%s", HasNewMail() and sf("%sNew mail!|r", classColor) or "No mail")
	RefreshFrame(mail, db.mail)
end
local function updateSocial()
	local gCount, fCount = 0, 0
	if IsInGuild() then
		for i = 0, GetNumGuildMembers(true) do 
			if select(9, GetGuildRosterInfo(i)) then gCount = gCount + 1 end
		end
	end
	
	local _, BNetOnline = BNGetNumFriends()
	for i = 0, GetNumFriends() do 
		if select(5, GetFriendInfo(i)) then fCount = fCount + 1 end
	end
	fCount = fCount + BNetOnline
	
	local gstring = IsInGuild() and sf("%sGuild:|r %d", classColor, gCount) or "No Guild"
	local fstring = sf("%sFriend:|r %d", classColor, fCount)
	social.string:SetFormattedText("%s / %s", fstring, gstring)
	RefreshFrame(social, db.social)
	friendsOnline, guildiesOnline = fCount, gCount
end
--[[ ----------------- ]]

local function RefreshValues(item)
	if 		item == clock 	then updateClock()
	elseif  item == fps 	then updateFPS()
	elseif  item == lag 	then updateLag()
	elseif  item == mem 	then updateMem()
	elseif  item == money 	then updateMoney(); updateCurrency()
	elseif  item == xp 		then updateXP()
	elseif  item == bag 	then updateBag() 
	elseif  item == dura 	then updateDura()
	elseif  item == mail  	then updateMail()
	elseif  item == social 	then updateSocial() end
end

--[[ -----Movement Functions----- ]]
local function TranslateCoords(frame, aF, aP, x, y)
    local y1, x1
	-- Handle Y-axis
    if      ( aF == "TOP" or aF == "TOPLEFT" or aF == "TOPRIGHT" ) then                             	y1 = frame:GetHeight()/2; y = y - y1
    elseif  ( aF == "BOTTOM" or aF == "BOTTOMLEFT" or aF == "BOTTOMRIGHT" ) then                    	y1 = frame:GetHeight()/2; y = y + y1 end
	-- Handle X-axis
    if      ( aP == "RIGHT" 	and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then   x = x
    elseif  ( aP == "RIGHT" 	and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then      x1 = frame:GetWidth(); x = x + x1
    elseif  ( aP == "RIGHT" 	and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then            x1 = frame:GetWidth()/2; x = x + x1
    elseif  ( aP == "LEFT" 		and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then   x1 = frame:GetWidth(); x = x - x1
    elseif  ( aP == "LEFT" 		and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then      x = x
    elseif  ( aP == "LEFT" 		and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then            x1 = frame:GetWidth()/2; x = x - x1
    elseif  ( aP == "CENTER" 	and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then     	x1 = frame:GetWidth()/2; x = x + x1
    elseif  ( aP == "CENTER" 	and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then  	x1 = frame:GetWidth()/2; x = x - x1
    elseif  ( aP == "CENTER" 	and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then           	x = x end
    return x, y
end
local function MoveFrame(frame, itemDB)
	frame:SetPoint(itemDB.aP, itemDB.anch, itemDB.aF, itemDB.xOff, itemDB.yOff)
	frame:StartMoving()
end
local function StopFrame(item, frame, itemDB)
	frame:StopMovingOrSizing()
	local _, _, aF, x, y = frame:GetPoint()
	local anch = frame:GetParent():GetName()
	local xOff, yOff = TranslateCoords(frame, aF, itemDB.aP, x, y)
	itemDB.aP, itemDB.anch, itemDB.aF, itemDB.xOff, itemDB.yOff = itemDB.aP, anch, aF, floor(xOff), floor(yOff)
end
--[[ ---------------------------- ]]

local function setaPJust(item, itemDB, dbitem)
	local cur = itemDB[dbitem];
	if cur == "LEFT" then 
		itemDB.aP = "CENTER"; itemDB.xOff = itemDB.xOff + (item.frame:GetWidth()/2)
	elseif cur == "CENTER" then
		itemDB.aP = "RIGHT"; itemDB.xOff = itemDB.xOff + (item.frame:GetWidth()/2)
	elseif cur == "RIGHT" then
		itemDB.aP = "LEFT"; itemDB.xOff = itemDB.xOff - (item.frame:GetWidth())
	end
end

local function CheckModifier()
	local modifier = nil
	local ctrl, shft, alt = IsControlKeyDown(), IsShiftKeyDown(), IsAltKeyDown()
	if ctrl then modifier = "Control" end
	if shft then modifier = "Shift" end
	if alt then modifier = "Alt" end
	if ctrl and shft or ctrl and alt or shft and alt then
		err("Cannot use two modifiers, voiding modifier")
		modifier = nil
	end
	return modifier
end

local function ProcessClick(item, itemDB, button)
	local modifier = CheckModifier()
	local dbitem = Click:ActClick(item.frame, button, modifier)
	if dbitem then
		if dbitem == "aP" then setaPJust(item, itemDB, dbitem) else itemDB[dbitem] = not itemDB[dbitem] end
	end
	RefreshValues(item)
end

local ttindex = {
	["BOTTOMLEFT"] = "ANCHOR_TOPLEFT", ["BOTTOM"] = "ANCHOR_TOP", ["BOTTOMRIGHT"] = "ANCHOR_TOPRIGHT",
	["LEFT"] = "ANCHOR_RIGHT", ["CENTER"] = "ANCHOR_TOP", ["RIGHT"] = "ANCHOR_LEFT",
	["TOPLEFT"] = "ANCHOR_BOTTOMRIGHT", ["TOP"] = "ANCHOR_BOTTOM", ["TOPRIGHT"] = "ANCHOR_BOTTOMLEFT",
}

local function SetTip(item, frame)
	if item == clock then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.clock.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.clock.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.clock.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", sf("Toggle 24/12 Hour |cffffff00(%s)|r", db.clock.format24 and "24" or "12"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Right-Click", sf("Toggle Realm/Local Time |cffffff00(%s)|r", db.clock.realmTime and "Realm" or "Local"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.clock.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down |cffffff00(%i)|r", db.clock.fontSize), 1,1,0,1,1,1)
			else
				GameTooltip:AddLine(sf("%s %i, %i", date("%B"), date("%d"), date("%Y")))
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Realm Time", sf("%s%s", select(1, getGameTime()), select(2, getGameTime())), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Local Time", locTime, 1,1,0,1,1,1)
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Left-Click", "Toggle Calendar", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", "Toggle Time Manager", 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == fps then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.fps.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.fps.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.fps.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.fps.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.fps.fontSize), 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == lag then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.lag.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.lag.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.lag.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.lag.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.lag.fontSize), 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == mem then
		frame:SetScript("OnEnter", function(this)
			local function sortdesc(a, b) return a[2] > b[2] end
			GameTooltip:SetOwner(this, ttindex[db.mem.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.mem.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.mem.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.mem.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.mem.fontSize), 1,1,0,1,1,1)
			else
				local addons, total = {}, 0
				for i = 1, GetNumAddOns() do
					if IsAddOnLoaded(i) then
						local memUse = GetAddOnMemoryUsage(i)
						table.insert(addons, { GetAddOnInfo(i), memUse })
						total = total + memUse
					end
				end
				table.sort(addons, sortdesc)
				GameTooltip:AddLine(sf("AddOn Memory: %.1fmb", total/1024))
				if not IsAltKeyDown() then GameTooltip:AddLine("Showing top 15 AddOns") end
				GameTooltip:AddLine(" ")
				for i = 1, #addons do
					if i <= 15 and not IsAltKeyDown() then
						local v = addons[i]
						local tag, memAmt
						if v[2]/1024 < 1 then tag = "kb"; memAmt = v[2] else tag = "mb"; memAmt = v[2]/1024 end
						GameTooltip:AddDoubleLine(v[1], sf("%.1f%s", memAmt, tag), 1,1,0,1,1,1)
					elseif IsAltKeyDown() then
						local v = addons[i]
						local tag, memAmt
						if v[2]/1024 < 1 then tag = "kb"; memAmt = v[2] else tag = "mb"; memAmt = v[2]/1024 end
						GameTooltip:AddDoubleLine(v[1], sf("%.1f%s", memAmt, tag), 1,1,0,1,1,1)
					end
				end
				GameTooltip:AddDoubleLine("", "----------", 1,1,1,1,1,1)
				GameTooltip:AddDoubleLine("Total AddOn Memory:", sf("%.1fmb", total/1024), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Total UI Memory Usage:", sf("%.1fmb", gcinfo()/1024), 1,1,0,1,1,1)
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Left-Click", "Show only top AddOns", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Left-Click", "Show all AddOns", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", "Collect Garbage", 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == money then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.money.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.money.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.money.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", sf("Cycle display style. |cffffff00(Current: %s)|r", db.money.dispSty and "Long" or "Short"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.money.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.money.fontSize), 1,1,0,1,1,1)
			else
				local current, sessStart, sessEarn = convertMoney(curGold, "Long"), convertMoney(goldStart, "Long"), convertMoney(goldEarned, "Long")
				GameTooltip:AddLine(sf("%s's wallet", UnitName("player")))
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Current:", sf("%s", current), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Session Start:", sf("%s", sessStart), 1,1,0,1,1,1)
				if ( curGold < goldStart ) then sessEarn = sf("|cffffff00-(|r%s|cffffff00)|r", sessEarn) end
				GameTooltip:AddDoubleLine("Session Earned:", sf("%s", sessEarn), 1,1,0,1,1,1)
				local isCurr = false
				for k, v in pairs(currTable) do
					if v > 0 then
						if not isCurr then GameTooltip:AddLine(" "); isCurr = not isCurr end
						GameTooltip:AddDoubleLine(k, v, 1,1,0,1,1,1)
					end
				end
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == xp then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.xp.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.xp.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.xp.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", sf("Cycle display style. |cffffff00(Current: %s)|r", db.xp.dispSty and "Text" or "Bar"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.xp.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.xp.fontSize), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", sf("Bar Width Factor Up/Down (%i)", db.xp.wF), 1,1,0,1,1,1)
			else
				GameTooltip:AddDoubleLine("Experience", sf("Lv.%d", UnitLevel("player")), 1,1,0,1,1,1)
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Current/Max XP:", sf("%s/%s", getXPStr("cur"), getXPStr("max")), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Remaining XP:", sf("%s %s", getXPStr("rem"), getXPStr("perR")), 1,1,0,1,1,1)
				if GetXPExhaustion() then GameTooltip:AddDoubleLine("Rest XP:", sf("%s%s", getXPStr("rest"), getXPStr("rper")), 1,1,0,1,1,1) end
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == bag then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.bag.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.bag.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.bag.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Right-Click", sf("Toggle Autosell Junk on/off |cffffff00(Current: %s)|r", db.bag.autosell and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.bag.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.bag.fontSize), 1,1,0,1,1,1)
			else
				local bagRem, bagTtl = 0, 0
				for i = 0, NUM_BAG_SLOTS do
					bagRem, bagTtl = bagRem + GetContainerNumFreeSlots(i), bagTtl + GetContainerNumSlots(i)
				end
				GameTooltip:AddLine("Bag Tracker")
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Space Used:", sf("%d", bagTtl - bagRem), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Space Avail:", sf("%d", bagTtl), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Space Left:", sf("%d", bagRem), 1,1,0,1,1,1)
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("AutoSell Junk:", sf("%s", db.bag.autosell and "On" or "Off"), 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == dura then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.dura.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.dura.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", sf("Toggle Auto Repair on/off |cffffff00(Current: %s)|r", db.dura.autorepair and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.dura.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.dura.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.dura.fontSize), 1,1,0,1,1,1)
			else
				GameTooltip:AddLine("Durability")
				GameTooltip:AddLine(" ")
				local durFull = true
				for slot, slotName in gmatch("1HEAD3SHOULDER5CHEST6WAIST7LEGS8FEET9WRIST10HANDS16MAINHAND17SECONDARYHAND18RANGED","(%d+)([^%d]+)") do
					local durCur, durMax = GetInventoryItemDurability(slot)
					local slotName = _G[slotName.."SLOT"]
					if durCur ~= durMax then
						GameTooltip:AddDoubleLine(slotName, sf("%.0f%%", durCur ~= 0 and durCur*(100/durMax) or 0), 1,1,0,1,1,1)
						if durFull then durFull = false end
					end
				end
				if durFull then
					GameTooltip:AddDoubleLine("All Items:", "100%", 1,1,0,1,1,1)
				end
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("AutoRepair:", sf("%s", db.dura.autorepair and "On" or "Off"), 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == mail then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.mail.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.mail.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.mail.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.mail.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.mail.fontSize), 1,1,0,1,1,1)
			else
				if not HasNewMail() then return end
				MinimapMailFrameUpdate()
				GameTooltip:Show()
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	elseif item == social then
		frame:SetScript("OnEnter", function(this)
			GameTooltip:SetOwner(this, ttindex[db.social.aF])
			if db.general.moving then
				GameTooltip:AddLine("Move Mode")
				GameTooltip:AddDoubleLine("Left-Click", "Move Frame", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Alt+Mousewheel Up/Down", "Tweak Vertical Pos", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Mousewheel Up/Down", "Tweak Horizontal Pos", 1,1,0,1,1,1)
			elseif db.general.confMode then
				GameTooltip:AddLine("Config Mode")
				GameTooltip:AddDoubleLine("Alt+Left-Click", sf("Toggle combat fading on/off |cffffff00(Current: %s)|r", db.social.cbfade and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Left-Click", sf("Cycle text justification. |cffffff00(Current: %s)|r", db.social.aP), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Shift+Right-Click", sf("Toggle text outline |cffffff00(Current: %s)|r", db.social.outline and "On" or "Off"), 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Mousewheel Up/Down", sf("Font Size Up/Down (%i)", db.social.fontSize), 1,1,0,1,1,1)
			else
				GameTooltip:AddDoubleLine("Social", sf("(%s)", IsInGuild() and GetGuildInfo("player") or "No Guild"))
				GameTooltip:AddLine(" ")
				if db.social.showF and friendsOnline > 0 then
					local numBNet, numBNetOn = BNGetNumFriends()
					local frTotal, frOnline = 0, GetNumFriends()
					for i = 0, frTotal do if select(5, GetFriendInfo(i)) then frOnline = frOnline + 1 end end
					frOnline = frOnline + numBNetOn
					if frOnline > 0 then
						GameTooltip:AddLine("Friends Online:")
						local friends = {}
						for j = 1, numBNetOn do
							local presenceID, givenName, surname, toonName, toonID, client, connected, lastOnline, isAFK, isDND, broadcastText, noteText, isFriend, broadcastTime = BNGetFriendInfo(j)
							local numToons = BNGetNumFriendToons(j)
							for k = 1, numToons do
								local hasFocus, name, client, realmName, faction, race, class, guild, zone, level, gameText = BNGetFriendToonInfo(j,k)
								if not connected then break end; tinsert(friends, name)
								if client == "WoW" then
									class = getClass(class)
									local cCol = sf("|cff%02X%02X%02X", RAID_CLASS_COLORS[class].r*255, RAID_CLASS_COLORS[class].g*255, RAID_CLASS_COLORS[class].b*255)
									GameTooltip:AddDoubleLine(sf("|cffffffff[%d]|r %s%s|r", level, cCol, name), sf("|cffffffff%s %s|r", status or "", zone))
								else
									GameTooltip:AddDoubleLine(sf("%s %s", givenName, surname), client, 1,1,1,1,1,1)
								end
							end
						end
						for m = 1, GetNumFriends() do
							local name, level, class, zone, connected, status, note = GetFriendInfo(m)
							if class ~= "UNKNOWN" then
								class = getClass(class)
								local cCol = sf("|cff%02X%02X%02X", RAID_CLASS_COLORS[class].r*255, RAID_CLASS_COLORS[class].g*255, RAID_CLASS_COLORS[class].b*255)
								if not connected then break end
								if not tContains(friends, name) then
									GameTooltip:AddDoubleLine(sf("|cffffffff[%d]|r %s%s|r", level, cCol, name), sf("|cffffffff%s %s|r", status or "", zone))
								end
							end
						end
						GameTooltip:AddLine(" ")
					end
				end
				if db.social.showG and guildiesOnline > 0 then
					GuildRoster()
					if IsInGuild() then
						GameTooltip:AddLine(sf("%s", GetGuildRosterMOTD()))
						for i = 0, GetNumGuildMembers(true) do
							if select(9, GetGuildRosterInfo(i)) and select(1, GetGuildRosterInfo(i)) ~= UnitName("player") then 
								local name, rank, _, level, _, zone, note, officernote, connected, status, class = GetGuildRosterInfo(i)
								class = getClass(class)
								local cCol = sf("|cff%02X%02X%02X", RAID_CLASS_COLORS[class or "PRIEST"].r*255, RAID_CLASS_COLORS[class or "PRIEST"].g*255, RAID_CLASS_COLORS[class or "PRIEST"].b*255)
							end
						end
					else
						GameTooltip:AddLine("No Guild")
					end
				end
				GameTooltip:AddLine(" ")
				GameTooltip:AddDoubleLine("Left-Click", "Toggle Guild Pane", 1,1,0,1,1,1)
				GameTooltip:AddDoubleLine("Right-Click", "Toggle Friend Pane", 1,1,0,1,1,1)
			end
			GameTooltip:Show()
		end)
		frame:SetScript("OnLeave", function(this)
			if GameTooltip:IsShown() then GameTooltip:Hide() end
		end)
	end
end

local function SetScrollFunc(item, frame, itemDB)
	frame:SetScript("OnMouseWheel", function(self, delta)
		if db.general.confMode then
			if IsShiftKeyDown() and item == xp then
				if delta > 0 then -- Up
					itemDB.wF = itemDB.wF + 1; updateXP()
					self:GetScript("OnEnter")(self)
				elseif delta < 0 then -- Down
					itemDB.wF = itemDB.wF - 1; updateXP()
					self:GetScript("OnEnter")(self)
				end
			else
				if delta > 0 then -- Up
					itemDB.fontSize = itemDB.fontSize + 1
					RefreshFrame(item, itemDB)
					self:GetScript("OnEnter")(self)
				elseif delta < 0 then -- Down
					itemDB.fontSize = itemDB.fontSize - 1
					RefreshFrame(item, itemDB)
					self:GetScript("OnEnter")(self)
				end
			end
		elseif db.general.moving then
			if delta > 0 then -- Up
				if IsShiftKeyDown() then
					itemDB.xOff = itemDB.xOff + 1
					RefreshFrame(item, itemDB)
				elseif IsAltKeyDown() then
					itemDB.yOff = itemDB.yOff + 1
					RefreshFrame(item, itemDB)
				end
				self:GetScript("OnEnter")(self)
			elseif delta < 0 then -- Down
				if IsShiftKeyDown() then
					itemDB.xOff = itemDB.xOff - 1
					RefreshFrame(item, itemDB)
				elseif IsAltKeyDown() then
					itemDB.yOff = itemDB.yOff - 1
					RefreshFrame(item, itemDB)
				end
				self:GetScript("OnEnter")(self)
			end
		end
	end)
end

--[[ -----Combat Fade Functions----- ]]
local function fadeOut(item, itemDB)
	if not itemDB.enabled then return end
	local step = 0.05
	local frame, fadeFr = item.frame, item.fadeFrame
	if itemDB.cbfade then
		if frame:GetAlpha() > 0 then
			fadeFr:SetScript("OnUpdate", function()
				if frame:GetAlpha() <= 1.0 and frame:GetAlpha() ~= 0 then
					frame:SetAlpha(frame:GetAlpha()-step)
				elseif frame:GetAlpha() == 0 then
					frame:Hide()
					fadeFr:SetScript("OnUpdate", nil)
				end
			end)
		end
	end
end
local function fadeIn(item)
	if item.frame == nil then return end
	local step = 0.05
	local frame, fadeFr = item.frame, item.fadeFrame
	if not frame:IsShown() then frame:Show() end
	if frame:GetAlpha() == 0 then
		fadeFr:SetScript("OnUpdate", function()
			if frame:GetAlpha() < 1.0 then
				frame:SetAlpha(frame:GetAlpha()+step)
			elseif frame:GetAlpha() == 1.0 then
				fadeFr:SetScript("OnUpdate", nil)
			end
		end)
	end
end
local function SetFade(item, itemDB)
	if not item.fadeFrame then item.fadeFrame = CreateFrame("Frame") end
	item.fadeFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
	item.fadeFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
	item.fadeFrame:SetScript("OnEvent", function(self, event)
		if event == "PLAYER_REGEN_ENABLED" then
			fadeIn(item)
		elseif event == "PLAYER_REGEN_DISABLED" then
			fadeOut(item, itemDB)
		end
	end)
end
--[[ ------------------------------- ]]

local function Setup(item)
	if item == clock and db.clock.enabled then
		if not clock.frame then Build(clock, db.clock) end
		clock.frame:SetScript("OnUpdate", function(_, elapsed)
			clock.int = clock.int - elapsed; if clock.int <= 0 then updateClock(); clock.int = 2 end
		end)
		Click:NewClickCmd(clock.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(clock.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(clock.frame, "LeftButton", "Control", "anchor")
		Click:NewClickCmd(clock.frame, "RightButton", nil, "format24")
		Click:NewClickCmd(clock.frame, "RightButton", "Alt", "realmTime")
		Click:NewClickCmd(clock.frame, "RightButton", "Shift", "outline")
		clock.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(clock.frame, db.clock) end
			elseif db.general.confMode then
				ProcessClick(clock, db.clock, button)
			else
				-- Action during normal state
				if button == "LeftButton" then
					ToggleCalendar()
				elseif button == "RightButton" then
					ToggleTimeManager()
				end
			end
			self:GetScript("OnEnter")(self)
		end)
		clock.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(clock, clock.frame, db.clock) end
		end)
		SetScrollFunc(clock, clock.frame, db.clock)
		SetTip(clock, clock.frame); SetFade(clock, db.clock)
		clock.frame:EnableMouse(true); clock.frame:EnableMouseWheel(true)
		clock.frame:SetMovable(true); clock.frame:SetClampedToScreen(true)
		TimeManagerClockButton:Hide()
		RefreshValues(clock)
	elseif item == fps and db.fps.enabled then
		if not fps.frame then Build(fps, db.fps) end
		fps.frame:SetScript("OnUpdate", function(_, elapsed)
			fps.int = fps.int - elapsed; if fps.int <= 0 then updateFPS(); fps.int = 2 end
		end)
		Click:NewClickCmd(fps.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(fps.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(fps.frame, "RightButton", "Shift", "outline")
		fps.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(fps.frame, db.fps) end
			elseif db.general.confMode then
				ProcessClick(fps, db.fps, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		fps.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(fps, fps.frame, db.fps) end
		end)
		SetScrollFunc(fps, fps.frame, db.fps)
		SetTip(fps, fps.frame); SetFade(fps, db.fps)
		fps.frame:EnableMouse(false); fps.frame:EnableMouseWheel(true)
		fps.frame:SetMovable(true); fps.frame:SetClampedToScreen(true)
		RefreshValues(fps)
	elseif item == lag and db.lag.enabled then
		if not lag.frame then Build(lag, db.lag) end
		lag.frame:SetScript("OnUpdate", function(_, elapsed)
			lag.int = lag.int - elapsed; if lag.int <= 0 then updateLag(); lag.int = 2 end
		end)
		Click:NewClickCmd(lag.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(lag.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(lag.frame, "RightButton", "Shift", "outline")
		lag.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(lag.frame, db.lag) end
			elseif db.general.confMode then
				ProcessClick(lag, db.lag, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		lag.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(lag, lag.frame, db.lag) end
		end)
		SetScrollFunc(lag, lag.frame, db.lag)
		SetTip(lag, lag.frame); SetFade(lag, db.lag)
		lag.frame:EnableMouse(false); lag.frame:EnableMouseWheel(true)
		lag.frame:SetMovable(true); lag.frame:SetClampedToScreen(true)
		RefreshValues(lag)
	elseif item == mem and db.mem.enabled then
		if not mem.frame then Build(mem, db.mem) end
		mem.frame:SetScript("OnUpdate", function(_, elapsed)
			mem.int = mem.int - elapsed; if mem.int <= 0 then updateMem(); mem.int = 10 end
		end)
		Click:NewClickCmd(mem.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(mem.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(mem.frame, "RightButton", "Shift", "outline")
		mem.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(mem.frame, db.mem) end
			elseif db.general.confMode then
				ProcessClick(mem, db.mem, button)
			else
				-- Action during normal state
				if button == "RightButton" then collectgarbage() end
			end
			self:GetScript("OnEnter")(self)
		end)
		mem.frame:SetScript("OnMouseUp", function()
			if db.general.moving then StopFrame(mem, mem.frame, db.mem) end
		end)
		SetScrollFunc(mem, mem.frame, db.mem)
		SetTip(mem, mem.frame); SetFade(mem, db.mem)
		mem.frame:EnableMouse(true); mem.frame:EnableMouseWheel(true)
		mem.frame:SetMovable(true); mem.frame:SetClampedToScreen(true)
		RefreshValues(mem)
	elseif item == money and db.money.enabled then
		if not money.frame then Build(money, db.money) end
		money.frame:RegisterEvent("PLAYER_MONEY")
		money.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
		money.frame:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
		money.frame:SetScript("OnEvent", function(self, event, ...)
			if event == "CURRENCY_DISPLAY_UPDATE" then
				updateCurrency()
			else
				updateMoney()
			end
		end)
		Click:NewClickCmd(money.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(money.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(money.frame, "RightButton", nil, "dispSty")
		Click:NewClickCmd(money.frame, "RightButton", "Shift", "outline")
		--Click:NewClickCmd(money.frame, "RightButton", "Alt", "curDisp")
		money.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(money.frame, db.money) end
			elseif db.general.confMode then
				ProcessClick(money, db.money, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		money.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(money, money.frame, db.money) end
		end)
		SetScrollFunc(money, money.frame, db.money)
		SetTip(money, money.frame); SetFade(money, db.money)
		money.frame:EnableMouse(true); money.frame:EnableMouseWheel(true)
		money.frame:SetMovable(true); money.frame:SetClampedToScreen(true)
		RefreshValues(money)
	elseif item == xp and db.xp.enabled then
		if not xp.frame then Build(xp, db.xp) end
		--xp.frame:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
		xp.frame:RegisterEvent("PLAYER_XP_UPDATE")
		xp.frame:RegisterEvent("PLAYER_LEVEL_UP")
		xp.frame:RegisterEvent("UPDATE_FACTION")
		xp.frame:SetScript("OnEvent", function(_, event, ...) updateXP(event, ...) end)
		Click:NewClickCmd(xp.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(xp.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(xp.frame, "RightButton", nil, "dispSty")
		Click:NewClickCmd(xp.frame, "RightButton", "Shift", "outline")
		xp.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(xp.frame, db.xp) end
			elseif db.general.confMode then
				ProcessClick(xp, db.xp, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		xp.frame:SetScript("OnMouseUp", function()
			if db.general.moving then StopFrame(xp, xp.frame, db.xp) end
		end)
		SetScrollFunc(xp, xp.frame, db.xp)
		SetTip(xp, xp.frame); SetFade(xp, db.xp)
		xp.frame:EnableMouse(true); xp.frame:EnableMouseWheel(true)
		xp.frame:SetMovable(true); xp.frame:SetClampedToScreen(true)
		RefreshValues(xp)
	elseif item == bag and db.bag.enabled then
		if not bag.frame then Build(bag, db.bag) end
		bag.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
		bag.frame:RegisterEvent("BAG_UPDATE")
		bag.frame:RegisterEvent("MERCHANT_SHOW")
		bag.frame:SetScript("OnEvent", function(_, event)
			if event == "MERCHANT_SHOW" and db.bag.autosell then
				local junkMon = 0
				for bag = 0, NUM_BAG_SLOTS do 
					for slot = 0, GetContainerNumSlots(bag) do
						local link = GetContainerItemLink(bag, slot)
						if link then
							if select(3, GetItemInfo(link)) == 0 then
								junkMon = junkMon + select(11, GetItemInfo(link)) * select(2, GetContainerItemInfo(bag, slot))
								UseContainerItem(bag, slot)
							end
						end
					end
				end
				if junkMon > 0 then print(sf("|cffffff00SLDT|r - AutoSell Earned: %s", convertMoney(junkMon, true))) end
			else
				updateBag()
			end
		end)
		Click:NewClickCmd(bag.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(bag.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(bag.frame, "RightButton", "Alt", "autosell")
		Click:NewClickCmd(bag.frame, "RightButton", "Shift", "outline")
		bag.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(bag.frame, db.bag) end
			elseif db.general.confMode then
				ProcessClick(bag, db.bag, button)
			else
				OpenAllBags()
			end
			self:GetScript("OnEnter")(self)
		end)
		bag.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(bag, bag.frame, db.bag) end
		end)
		SetScrollFunc(bag, bag.frame, db.bag)
		SetTip(bag, bag.frame); SetFade(bag, db.bag)
		bag.frame:EnableMouse(true); bag.frame:EnableMouseWheel(true)
		bag.frame:SetMovable(true); bag.frame:SetClampedToScreen(true)
		RefreshValues(bag)
	elseif item == dura and db.dura.enabled then
		if not dura.frame then Build(dura, db.dura) end
		dura.frame:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
		dura.frame:RegisterEvent("MERCHANT_SHOW")
		dura.frame:SetScript("OnEvent", function(_, event)
			if event == "MERCHANT_SHOW" and db.dura.autorepair and CanMerchantRepair() then
				local repCost, totCost = GetRepairAllCost(), 0
				if repCost > 0 then
					RepairAllItems()
					print(sf("|cffffff00SLDT|r - Items repaired for %s.", convertMoney(repCost, true)))
				end
			else
				updateDura()
			end
		end)
		Click:NewClickCmd(dura.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(dura.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(dura.frame, "RightButton", nil, "autorepair")
		Click:NewClickCmd(dura.frame, "RightButton", "Shift", "outline")
		dura.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(dura.frame, db.dura) end
			elseif db.general.confMode then
				ProcessClick(dura, db.dura, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		dura.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(dura, dura.frame, db.dura) end
		end)
		SetScrollFunc(dura, dura.frame, db.dura)
		SetTip(dura, dura.frame); SetFade(dura, db.dura)
		dura.frame:EnableMouse(true); dura.frame:EnableMouseWheel(true)
		dura.frame:SetMovable(true); dura.frame:SetClampedToScreen(true)
		RefreshValues(dura)
	elseif item == mail and db.mail.enabled then
		if not mail.frame then Build(mail, db.mail) end
		MiniMapMailFrame.Show = MiniMapMailFrame.Hide
		mail.frame:SetScript("OnUpdate", function(_, elapsed)
			mail.int = mail.int - elapsed; if mail.int <= 0 then updateMail(); mail.int = 10 end
		end)
		Click:NewClickCmd(mail.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(mail.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(mail.frame, "RightButton", "Shift", "outline")
		mail.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(mail.frame, db.mail) end
			elseif db.general.confMode then
				ProcessClick(mail, db.mail, button)
			else
				-- Action during normal state
			end
			self:GetScript("OnEnter")(self)
		end)
		mail.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(mail, mail.frame, db.mail) end
		end)
		SetScrollFunc(mail, mail.frame, db.mail)
		SetTip(mail, mail.frame); SetFade(mail, db.mail)
		mail.frame:EnableMouse(true); mail.frame:EnableMouseWheel(true)
		mail.frame:SetMovable(true); mail.frame:SetClampedToScreen(true)
		RefreshValues(mail)
	elseif item == social and db.social.enabled then
		if not social.frame then Build(social, db.social) end
		social.frame:SetScript("OnUpdate", function(_, elapsed)
			social.int = social.int - elapsed; if social.int <= 0 then updateSocial(); social.int = 5 end
		end)
		Click:NewClickCmd(social.frame, "LeftButton", "Alt", "cbfade")
		Click:NewClickCmd(social.frame, "LeftButton", "Shift", "aP")
		Click:NewClickCmd(social.frame, "RightButton", "Shift", "outline")
		social.frame:SetScript("OnMouseDown", function(self, button)
			if db.general.moving then
				if button == "LeftButton" then MoveFrame(social.frame, db.social) end
			elseif db.general.confMode then
				ProcessClick(social, db.social, button)
			else
				if button == "LeftButton" then
					ToggleGuildFrame(1)
				elseif button == "RightButton" then
					ToggleFriendsPanel()
				end
			end
			self:GetScript("OnEnter")(self)
		end)
		social.frame:SetScript("OnMouseUp", function(_, button)
			if db.general.moving then StopFrame(social, social.frame, db.social) end
		end)
		SetScrollFunc(social, social.frame, db.social)
		SetTip(social, social.frame); SetFade(social, db.social)
		social.frame:EnableMouse(true); social.frame:EnableMouseWheel(true)
		social.frame:SetMovable(true); social.frame:SetClampedToScreen(true)
		RefreshValues(social)
	end
end

local function ChangeMode(item, state, norm)
	if state then
		item:EnableMouse(true); item:SetBackdropColor(0,0,0,1)
	else
		if not norm then item:EnableMouse(false) end
		item:SetBackdropColor(0,0,0,0)
	end
end

local function GlobalUpdate()
	if db.general.confMode or db.general.moving then
		if db.clock.enabled then ChangeMode(clock.frame, true) end
		if db.fps.enabled then ChangeMode(fps.frame, true) end
		if db.lag.enabled then ChangeMode(lag.frame, true) end
		if db.mem.enabled then ChangeMode(mem.frame, true) end
		if db.money.enabled then ChangeMode(money.frame, true) end
		if db.xp.enabled then ChangeMode(xp.frame, true) end
		if db.bag.enabled then ChangeMode(bag.frame, true) end
		if db.dura.enabled then ChangeMode(dura.frame, true) end
		if db.mail.enabled then ChangeMode(mail.frame, true) end
		if db.social.enabled then ChangeMode(social.frame, true) end
	else
		if db.clock.enabled then ChangeMode(clock.frame, false, true) end
		if db.fps.enabled then ChangeMode(fps.frame, false, false) end
		if db.lag.enabled then ChangeMode(lag.frame, false, false) end
		if db.mem.enabled then ChangeMode(mem.frame, false, true) end
		if db.money.enabled then ChangeMode(money.frame, false, true) end
		if db.xp.enabled then ChangeMode(xp.frame, false, true) end
		if db.bag.enabled then ChangeMode(bag.frame, false, true) end
		if db.dura.enabled then ChangeMode(dura.frame, false, true) end
		if db.mail.enabled then ChangeMode(mail.frame, false, true) end
		if db.social.enabled then ChangeMode(social.frame, false, true) end
	end
end

local function enableTracker(item)
	Setup(item)
end
local function disableTracker(item)
	item.frame:UnregisterAllEvents()
	item.frame:Hide()
	if item.fadeFrame then item.fadeFrame = nil end
	item.string = nil; item.frame = nil
end

local function getItemDB(msg)
	local itemDB
	if 		msg == "Clock" 		then itemDB = db.clock
	elseif 	msg == "FPS" 		then itemDB = db.fps
	elseif 	msg == "Latency" 	then itemDB = db.lag
	elseif	msg == "Memory" 	then itemDB = db.mem
	elseif  msg == "Money"		then itemDB = db.money
	elseif	msg == "Experience"	then itemDB = db.xp
	elseif	msg == "Bag" 		then itemDB = db.bag 
	elseif	msg == "Durability" then itemDB = db.dura 
	elseif	msg == "Mail" 		then itemDB = db.mail 
	elseif	msg == "Social" 	then itemDB = db.social end
	return itemDB
end

SLASH_SLDT1 = "/sldt"
function SlashCmdList.SLDT(msg, _)
	local msg1, msgCmd = nil, nil
	if string.sub(msg, 0, 4) == "font" then
		local len = string.len(msg); msg1 = string.sub(msg, 0, 4); msgCmd = string.sub(msg, 6, len)
	elseif string.sub(msg, 0, 6) == "enable" then
		local len = string.len(msg); msg1 = string.sub(msg, 0, 6); msgCmd = string.sub(msg, 8, len)
	elseif string.sub(msg, 0, 7) == "disable" then
		local len = string.len(msg); msg1 = string.sub(msg, 0, 7); msgCmd = string.sub(msg, 9, len)
	elseif string.sub(msg, 0, 7) == "profile" then
		local len = string.len(msg); msg1 = string.sub(msg, 0, 7); msgCmd = string.sub(msg, 9, len)
	end
	if msg == "menu" then
		
	elseif msg == "config" then
		if db.general.moving then db.general.moving = false end
		db.general.confMode = not db.general.confMode
		print(sf("|cffffff00SLDT|r - Configuration mode now |cffffff00%s|r", db.general.confMode and "On" or "Off"))
		GlobalUpdate()
	elseif msg == "move" then
		if db.general.confMode then db.general.confMode = false end
		db.general.moving = not db.general.moving
		print(sf("|cffffff00SLDT|r - Moving mode now |cffffff00%s|r", db.general.moving and "On" or "Off"))
		GlobalUpdate()
	elseif msg == "font" then
		print(sf("|cffffff00SLDT|r - Type |cffffff00/sldt font <font name>|r to change global font. |cffffff00(Current: %s)|r", db.general.font))
		for k, v in pairs(Media:List("font")) do
			print(sf("- |cffffff00%s|r", v))
		end
	elseif msg == "profile" then
		print("|cffffff00Simple Light Data Text|r Profile Options:")
		print("- Type |cffffff00/sldt profile list|r to list valid profiles.")
		print("- Type |cffffff00/sldt profile save <or> load <profilename>|r to save or load a profile.")
		print("- Type |cffffff00/sldt profile over <profilename>|r to overwrite an existing profile (Warning...there is no going back!).")
	elseif msg == "classcolor" then
		db.general.classCol = not db.general.classCol
		if db.general.classCol then classColor = sf("|cff%02X%02X%02X", RAID_CLASS_COLORS[class].r*255, RAID_CLASS_COLORS[class].g*255, RAID_CLASS_COLORS[class].b*255) else classColor = "|cffffffff" end
		for k, v in pairs(SLDT_DEFAULTS) do
			if k ~= "general" then RefreshValues(SLDT_DEFAULTS[k]) end
		end
	elseif msg1 == nil then
		print("|cffffff00Simple Light Data Text|r v3.0.0 Options:")
		print(sf("- Type |cffffff00/sldt config|r to toggle configuration mode. |cffffff00(%s)|r", db.general.confMode and "On" or "Off"))
		print(sf("- Type |cffffff00/sldt move|r to toggle movement mode. |cffffff00(%s)|r", db.general.moving and "On" or "Off"))
		print(sf("- Type |cffffff00/sldt classcolor|r to toggle class coloring on/off. |cffffff00(Current: %s)|r", db.general.classCol and "On" or "Off"))
		print("- Type |cffffff00/sldt font|r to display font media list.")
		print(sf("- Type |cffffff00/sldt font <font name>|r to change global font. |cffffff00(Current: %s)|r", db.general.font))
		print("- Type |cffffff00/sldt enable <trackername>|r to enable tracker.")
		print("- Type |cffffff00/sldt disable <trackername>|r to disable tracker.")
		print("- Type |cffffff00/sldt profile|r for profile options.")
		print("- Valid Tracker Names:")
		local trackerstr = ""
		for k, v in pairs(SLDT_DEFAULTS) do
			if k ~= "general" and db[k].enabled then
				trackerstr = sf("%s %s", SLDT_DEFAULTS[k].enname, trackerstr)
			end
		end
		print(sf("  %s", trackerstr))
	end
	
	if msg1 == "font" then
		for k, v in pairs(Media:List("font")) do
			if v == msgCmd then
				db.general.font = v
				for k, v in pairs(SLDT_DEFAULTS) do
					if k ~= "general" then RefreshValues(SLDT_DEFAULTS[k]) end
				end
			end
		end
	elseif msg1 == "enable" then
		for k, v in pairs(SLDT_DEFAULTS) do
			if k ~= "general" and SLDT_DEFAULTS[k].enname == msgCmd then
				local itemDB = getItemDB(msgCmd); itemDB.enabled = true
				print(sf("|cffffff00SLDT|r %s enabled.", msgCmd))
				enableTracker(SLDT_DEFAULTS[k])
			end
		end
	elseif msg1 == "disable" then
		for k, v in pairs(SLDT_DEFAULTS) do
			if k ~= "general" and SLDT_DEFAULTS[k].enname == msgCmd then
				local itemDB = getItemDB(msgCmd); itemDB.enabled = false
				print(sf("|cffffff00SLDT|r %s disabled.", msgCmd))
				disableTracker(SLDT_DEFAULTS[k])
			end
		end
	elseif msg1 == "profile" then
		local sub, prof = string.sub(msgCmd, 0, 4), string.sub(msgCmd, 6, string.len(msgCmd))
		if sub == "list" then
			print("|cffffff00Simple Light Data Text|r Saved Profiles:")
			for k, v in pairs(pdb) do
				print(sf("- %s", k))
			end
		elseif sub == "save" then
			if pdb[prof] == nil then pdb[prof] = {} else print("|cffffff00SLDT|r - Profile exists, save aborted."); return end
			for k, v in pairs(db) do
				if pdb[prof][k] == nil then pdb[prof][k] = {} end
				for key, val in pairs(v) do
					if pdb[prof][k][key] == nil then
						pdb[prof][k][key] = val
					end
				end
			end
			print(sf("|cffffff00SLDT|r - %s profile saved.", prof))
		elseif sub == "over" then
			if pdb[prof] == nil then print("|cffffff00SLDT|r - Profile does not exist, overwrite aborted."); return end
			for k, v in pairs(db) do
				if pdb[prof][k] == nil then pdb[prof][k] = {} end
				for key, val in pairs(v) do
					if pdb[prof][k][key] == nil then
						pdb[prof][k][key] = val
					end
				end
			end
			print(sf("|cffffff00SLDT|r - %s profile overwritten.", prof))
		elseif sub == "load" then
			if prof == "Default" then
				for k, v in pairs(db) do
					for key, val in pairs(v) do
						db[k][key] = SLDT_DEFAULTS[k][key]
					end
				end
				for k, v in pairs(SLDT_DEFAULTS) do
					if k ~= "general" then RefreshValues(SLDT_DEFAULTS[k]) end
				end
				print("|cffffff00SLDT|r - Default profile loaded. Please reload your UI if some trackers have not updated.")
			else
				if pdb[prof] == nil then print("|cffffff00SLDT|r - Profile does not exist, load voided."); return end
				for k, v in pairs(db) do
					for key, val in pairs(v) do
						db[k][key] = pdb[prof][k][key]
					end
				end
				for k, v in pairs(SLDT_DEFAULTS) do
					if k ~= "general" then RefreshValues(SLDT_DEFAULTS[k]) end
				end
				print(sf("|cffffff00SLDT|r - %s profile loaded.", prof))
			end
		end
	end
end

local function OnInit()
	local realm, char = GetRealmName(), UnitName("player")
	class = select(2, UnitClass("player"))
	if not SLDTDB then SLDTDB = {} end
	if not SLDTDB[realm] then SLDTDB[realm] = {} end
	if not SLDTDB[realm][char] then SLDTDB[realm][char] = {} end
	db = SLDTDB[realm][char]
	-- Profiles
	if not SLDTDB["profiles"] then SLDTDB["profiles"] = {} end
	pdb = SLDTDB["profiles"]
	for k, v in pairs(SLDT_DEFAULTS) do
		if db[k] == nil then db[k] = {} end
		for key, val in pairs(v) do
			if db[k][key] == nil then 
				db[k][key] = val
			end
		end
	end
	-- Do this to force false config modes var on load
	db.general.confMode = false
	db.general.moving = false
	if db.general.classCol then classColor = sf("|cff%02X%02X%02X", RAID_CLASS_COLORS[class].r*255, RAID_CLASS_COLORS[class].g*255, RAID_CLASS_COLORS[class].b*255) end
	-- Setup all data trackers
	for k, v in pairs(SLDT_DEFAULTS) do
		if k ~= "general" then Setup(SLDT_DEFAULTS[k]) end
	end
	-- Kill Initilization func
	OnInit = nil
end

SLDT:RegisterEvent("PLAYER_ENTERING_WORLD")
SLDT:SetScript("OnEvent", OnInit)